package com.scs.application.modules.sys.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scs.application.core.mapper.IBaseMapper;
import com.scs.application.modules.sys.entity.Office;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;

/**
 * <p>
 *  机构 Mapper 接口
 * </p>
 */
public interface OfficeMapper extends IBaseMapper<Office> {
    @Select("SELECT * FROM (" +
            " SELECT ifnull(parent.name,'') parent_name, t.system_code,t.name,t.shortname,t.contact,t.manager,t.email,t.remark,t.id,t.parent_id" +
            " FROM sys_office t LEFT JOIN sys_office parent ON t.parent_id = parent.id) a" +
            " ${ew.customSqlSegment}")
    IPage<HashMap<String,Object>> getOfficeList(Page page, @Param(Constants.WRAPPER) Wrapper wrapper);
    @Select("SELECT MAX(system_code) FROM sys_office WHERE parent_id = #{parentId}")
    String getMaxOfficeCode(String parentId);
    @Delete("DELETE FROM sys_office WHERE parent_id = #{parentId}")
    String deleteChildOffice(String parentId);
}
